package com.goodlearning.gloriamobile.customdialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class BaseDialog extends Dialog{
	
	public Context context;
	public Callback callback;
	
	public BaseDialog(Context context,int layoutRes ,Callback callBack, boolean isCancel) {
		super(context,android.R.style.Theme_Translucent_NoTitleBar);
		this.context = context; 
		this.callback = callBack;
		
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
		
		//다이얼로그 설정
		setCancelable(isCancel);
		LinearLayout ll = (LinearLayout) LayoutInflater.from(context).inflate(layoutRes, null);
		LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
		addContentView(ll, lp);
		Paint paint = new Paint();
		paint.setColor(Color.BLACK);
		paint.setAlpha(70);
		ll.setBackgroundColor(paint.getColor());
		
	}

	/**
	 * 다이얼로그 결과 반환값 설정
	 */
	public Message getReturnValue() {
		return null;
	}
	
	/**
	 * 다이얼로그가 닫혀지면 콜백호출해준다.
	 */
	@Override
	public void onDetachedFromWindow() {
		super.onDetachedFromWindow();
		if(callback != null){
			callback.handleMessage(getReturnValue());
		}
		
	}

	@Override
	protected void onStop() {
		
	}
}